package airthmetic.exercise.sort.cmp;


// 选择排序 未AC 超时
public class _912_排序数组_Select {
    public int[] sortArray(int[] nums) {
        if(nums.length < 2){
            return nums;
        }
        int n = nums.length;
        for (int i = 0; i<n; i++){
            int min = i;
            for(int j=i+1; j<n; j++){
                if (nums[j] < nums[min]){
                    min = j;
                }
            }
            swap(nums, i, min);
        }
        return nums;
    }

    public void swap(int[] nums, int i, int j){
        if(i == j){
            return;
        }
        nums[i] ^= nums[j];
        nums[j] ^= nums[i];
        nums[i] ^= nums[j];
    }
}
